require 'logging'

if tests == nil then tests = {} end

local logName = "My Excellent Log"

local function create_log()
    local log = Log:create(logName)
    return true
end

local function get_log_by_name()
    local myLog = Log:getLog(logName)
    if (myLog) then return true end
end

local function print_to_log()
    local log = Log:getLog(logName)
    log:print("Testing!")
    return true
end

local function print_to_log_with_severity()
    local log = Log:getLog(logName)
    log:print("Kablooie!", Log.error)
    return true
end

local function get_anonymous_log_creates_log()
    local log = Log:getLog("Anonylog")
    log:print("Anonymous!")
    return true
end

tests.logging = {
    create_log = {
        description = "Creates a log to write into",
        test = create_log,
        prerequisites = {}
    },
    
    get_log_by_name = {
        description = "Gets a log by referring to it by name",
        test = get_log_by_name,
        prerequisites = {"create_log"}
    },
    
    print_to_log = {
        description = "Prints into a named log",
        test = print_to_log,
        prerequisites = {"create_log"}
    },
    
    print_to_log_with_severity  = {
        description = "Prints into a named log with severity values",
        test = print_to_log_with_severity,
        prerequisites = {"create_log"}
    },
    
    get_anonymous_log_creates_log   = {
        description = "Gets an undeclared log, creating it in the process",
        test = get_anonymous_log_creates_log,
        prerequisites = {"create_log"}
    },
}
